package cjq.demo.thread.ch4_3;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by cjianquan on 2016/4/27.
 */
public class Server {
    private ThreadPoolExecutor executor;

    public Server(){
        executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
    }

    public void executeTask(Task task){
        System.out.println("Server: Task Count: "+executor.getTaskCount());
        System.out.println("Server: A new task has arrived");
        executor.execute(task);
        System.out.println("Server: Pool Size: "+executor.getPoolSize());
        System.out.println("Server: Active Count: "+executor.getActiveCount());
        System.out.println("Server: Completed Tasks: "+executor.getCompletedTaskCount());
    }

    public void endServer(){
        executor.shutdown();
    }
}
